package com.hmall.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hmall.item.pojo.Item;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ItemMapper extends BaseMapper<Item> {
    /**
     * 查询所有
     * @return
     */
    @Select("select * from tb_item")
    List<Item> itemPageQuery();

    /**
     * 查询总数
     * @return
     */
    @Select("select count(*) from tb_item")
    Long getItemTotal();

    /**
     * 根据id查询商品信息
     * @param id
     * @return
     */
    @Select("select * from tb_item where id =#{id}")
    Item selectItemById(Long id);

    @Insert("insert into tb_item (name, price, stock, image, category, brand, spec, sold," +
            " comment_count, isAD, status, create_time, update_time)  values " +
            "(#{name},#{price},#{stock},#{image},#{category},#{brand},#{spec},#{sold}," +
            "#{commentCount},#{isAD},#{status},#{createTime},#{updateTime})")
    @Options(keyProperty = "id",useGeneratedKeys = true)
    void insertItem(Item item);

    void updateItem(Item item);

    @Delete("delete from tb_item where id = #{id}")
    void deleteItem(Long id);
}
